﻿using Inventory.Business.API;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Inventory.DAL;
using System;
using Inventory.Business;

namespace Inventory.Test
{    
    /// <summary>
    ///This is a test class for OpeningBalanceTransactionTest and is intended
    ///to contain all OpeningBalanceTransactionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class OpeningBalanceTransactionTest
    {
        OpeningBalanceTransaction transaction = new OpeningBalanceTransaction();


        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetById
        ///</summary>
        [TestMethod()]
        public void GetByIdTest()
        {
            var result = transaction.GetById(40);

            Assert.IsNotNull(result);
            Assert.AreNotEqual(0, result.Items.Count);
        }

        /// <summary>
        ///A test for Edit
        ///</summary>
        [TestMethod()]
        public void EditTest()
        {
            var result = transaction.GetById(41);

            //result.Code += "!";
            result.Items[0].Quantity = result.Items[0].Quantity * 2;

            Assert.IsTrue(transaction.Edit(result));
        }

        /// <summary>
        ///A test for Create
        ///</summary>
        [TestMethod()]
        public void CreateTest()
        {
            var result = transaction.Create(new Business.DomainObjects.OpeningBalance()
            {
                //Code = "UTest1",
                CreationDate = DateTime.Now,
                Status = Inventory.Business.DomainObjects.TransactionStatus.Open,
                Warehouse = 4,
                Items =
                {
                    new Inventory.Business.DomainObjects.OBMaterialItem()
                    {
                        Id=19102,
                        Area=Inventory.Business.DomainObjects.Area.Inventory,
                        Cost=1.1m,
                        Quantity=600
                    },
                    new Inventory.Business.DomainObjects.OBMaterialItem()
                    {
                        Id=19100,
                        Area=Inventory.Business.DomainObjects.Area.OnSite,
                        Cost=2.5m,
                        Quantity=202
                    }
                }
            });

            Assert.IsTrue(result);
        }

        /// <summary>
        ///A test for Commit
        ///</summary>
        [TestMethod()]
        public void CommitTest()
        {
            var OB = transaction.GetById(41);
            Assert.IsTrue(transaction.Commit(OB));
        }
    }
}
